using System;
using ObjectSync;
using ObjectSync.Interfaces;
using TestModel;
using System.Threading;


namespace TestClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Remote1 rem;
            //rem = (Remote1)RemoteManager.Instance.createRemoteObject(typeof(Remote1));
            rem = RemoteManager.createRemoteObject<Remote1>();

           
            
            //var t1 = new test1();
            ISyncable t1 = new test1();

            SyncManager.Instance.Register(ref t1);

            ISyncable t2 = new test1();
            ((test1)t2).Prop2 = 2;

            SyncManager.Instance.Register(ref t2);

            NetworkManager.Instance.StartClient("192.168.0.4", 17171);

			//while(NetworkManager.Instance.Communicator.getStatus() == comStatus.diconected);

            Console.WriteLine(rem.Teste());

            Console.WriteLine(rem.Teste2().Prop1);

            Console.WriteLine(rem.Teste3("Passagem por parametro").Prop1);
            
            ((test1)t1).Prop1 = "Teste1";

            ((test1)t1).Prop2 = 5;

            ((test1)t2).Prop2 = 6;


            SyncManager.Instance.Syncronize();
            int id = DateTime.Now.Millisecond;
            var r = new Random(id);
            for (int i = 0; i < 100; i++)
            {
                ((test1)t1).Prop1 = "ID:" + id;
                ((test1)t1).Prop2 = r.Next(100);
                SyncManager.Instance.Syncronize();
                Console.WriteLine("(SENDING) ID: " + id + " r:" + ((test1)t1).Prop2);
				Console.WriteLine("(RECEIVING) ID: " + ((test1)t2).Prop1 + " r:" + ((test1)t2).Prop2);
                Thread.Sleep(300);
                
            }
        }
    }
}
